package learningThread.syn.synchronizedMethodLockObj.lock.holdCount;
import	java.util.concurrent.locks.ReentrantLock;

/**
 * getHoldCount 返回当前线程保持此锁的个数,也就是调用 lock()方法的次数
 */
public class Service {

    private ReentrantLock lock = new ReentrantLock();

    public void serviceMethod(){
        try {
            lock.lock();
            System.out.println("serviceMethod1  getHoldCount="+lock.getHoldCount());
            serviceMethod2();
        } finally {
            lock.unlock();
        }
    }

    public void serviceMethod2(){
        try {
            lock.lock();
            System.out.println("serviceMethod2  getHoldCount="+lock.getHoldCount());
        } finally {
            lock.unlock();
        }

    }
}
